<template>
    <div>
        <h1>会员等级增加</h1>
        <table>
            <tr>
                <td align="right">等级名称</td>
                <td><input type="text" v-model="state.levelname" /></td>
            </tr>
            <tr>
                <td>最低消费金额</td>
                <td><input type="text" v-model="state.lowMoney" /></td>
            </tr>
            <tr>
                <td>最高消费金额</td>
                <td><input type="text" v-model="state.highMpney" /></td>
            </tr>
            <tr>
                <td>折扣</td>
                <td><input type="text" v-model="state.zhekou" /></td>
            </tr>
            <tr>
                <td>成长值</td>
                <td><input type="text" v-model="state.grow" /></td>
            </tr>
            <tr>
                <td>翻倍程度</td>
                <td><input type="text" v-model="state.speed" /></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="button" value="确定增加" @click="ok" /></td>
            </tr>
        </table>

    </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue'
import axios from 'axios'
const data = reactive({
    state: {
        levelname: '',
        lowMoney: '',
        highMpney: '',
        zhekou: '',
        grow: '',
        speed: ''
    }
})

const { state } = toRefs(data);

const ok = () => {
    if (state.value.levelname == '') {
        alert('不能为空')
        return
    }
    if (state.value.lowMoney == '') {
        alert('不能为空')
        return
    }
    if (state.value.highMpney == '') {
        alert('不能为空')
        return
    }
    if (state.value.zhekou == '') {
        alert('不能为空')
        return
    }
    if (state.value.grow == '') {
        alert('不能为空')
        return
    }
    if (state.value.speed == '') {
        alert('不能为空')
    }
   axios({
    url:'https://localhost:7144/api/Login/Memberlevl',
    method:'post',
    data:state.value
   })
   .then(res => {
   
    if(res.data.data ==1)
    {
         alert("添加成功")
    }else if(res.data.data ==-1)
    {
         alert("添加名称重复")
    }
    else{
        alert("添加失败")
    }
   
       
    })
    .catch((err) => {
       console.log(err)
    })
}


</script>

<style scoped></style>